<!--成绩录入-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label-width="100px" label="项目名称" prop="itemName">
        <el-select v-model="queryParams.itemName" placeholder="请选择项目名称" clearable>
          <el-option
            v-for="dict in dict.type.sport_item"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label-width="100px" label="项目类型" prop="itemType">
        <el-select v-model="queryParams.itemType" placeholder="请选择个人赛或团体赛" clearable>
          <el-option
            v-for="dict in dict.type.item_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="itemList">
      <el-table-column label="项目名称" align="center" prop="itemName">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sport_item" :value="scope.row.itemName"/>
        </template>
      </el-table-column>
      <el-table-column label="项目类型" align="center" prop="itemType">
        <template slot-scope="scope">
          <dict-tag ty :options="dict.type.item_type" :value="scope.row.itemType"/>
        </template>
      </el-table-column>
      <el-table-column label="项目比赛性别要求" align="center" prop="itemSex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.itemSex"/>
        </template>
      </el-table-column>
      <el-table-column label="项目比赛地点" align="center" prop="itemAddress">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.competition_set" :value="scope.row.itemAddress"/>
        </template>
      </el-table-column>
      <el-table-column label="项目比赛时间" align="center" prop="itemDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.itemDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目负责人姓名" align="center" prop="itemJudgementname"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >
            录入
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <add-score-dialog
      v-if="showDialog"
      ref="addScoreDialog"
      :dialog-title="dialogTitle"
      :item-info="tableItem"
      @closeDialog="closeDialog">
    </add-score-dialog>
  </div>
</template>

<script>
import {listItem} from "@/api/system/item";
import addScoreDialog from "@/views/components/sports/addScoreDialog";

export default {
  name: "Item",
  dicts: ['sys_user_sex', 'sport_item', 'competition_set', 'item_type'],
  components: {addScoreDialog},
  data() {
    return {
      tableItem: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹窗标题
      dialogTitle: "",
      // 显示弹窗
      showDialog: false,
      // 比赛项目表格数据
      itemList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        itemName: null,
        itemType: null,
        itemPeoNum: null,
        itemAddress: null,
        itemSex: null,
        itemDate: null,
        itemStardate: null,
        itemEnddate: null,
        itemJudgementid: null,
        itemJudgementname: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 跳转录入成绩弹窗 */
    handleUpdate(row) {
     this.tableItem = row;
     this.dialogTitle = "成绩录入";
     this.showDialog = true;
     this.$nextTick(() => {
       this.$refs["addScoreDialog"].showDialog = true;
     });
    },
    /** 查询比赛项目列表 */
    getList() {
      this.loading = true;
      listItem(this.queryParams).then(response => {
        this.itemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        itemName: null,
        itemAddress: null,
        itemSex: null,
        itemDate: null,
        itemStardate: null,
        itemEnddate: null,
        itemJudgementid: null,
        itemJudgementname: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 关闭操作
    closeDialog(flag) {
      if (flag) {
        // 重新刷新表格内容
        this.getList();
      }
      this.showDialog = false;
    },

  }
};
</script>
